<?php
/**
 * Created by PhpStorm.
 * User: lelouchms
 * Date: 2019/3/28
 * Time: 16:08
 */

namespace app\backend\controller\admin\v1;

use app\backend\controller\BackendController;
use app\common\constants\DBConstant;
use app\common\exception\CustomerException;
use app\common\exception\ValidateException;
use app\common\util\CommonUtil;

class User extends Base
{

    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\common\model\User();
    }

    public function getTypes()
    {
        return $this->model->getTypes();
    }

    public function update()
    {
        $requestData = $this->request->only(['type', 'phone', 'id', 'nickname',"remark"]);
        $validate = new \app\common\validate\User();
        $flag = $validate->scene("update")->check($requestData);
        if ($flag === false) {
            throw new ValidateException($validate->getError());
        }
        $count = $this->model->where("id", $requestData["id"])->update($requestData);
        if ($count > 1) throw new CustomerException("编辑失败");
        $this->_removeCache($requestData);
    }

    public function findById($id)
    {
        return $this->model->selectById($id, true);
    }



}